#include "RecvThread.h"

CRecvThread::CRecvThread(CInitParameter arg, QThread* parent)
	: QThread(parent)
	, m_arg(arg)
	, m_bIsRecv(true)
{

}

CRecvThread::~CRecvThread()
{

}

void CRecvThread::stopRecv()
{
	m_bIsRecv = false;
}

void CRecvThread::run()
{
	VCI_CAN_OBJ frameinfo[50];
	while (m_bIsRecv)
	{
		unsigned long len = VCI_Receive(m_arg.deviceType, m_arg.deviceIndex, m_arg.canIndex, frameinfo, 50, 200);
		if (len == 0xFFFFFFFF || len == 0)
		{
			continue;
		}
		for (unsigned int i = 0; i < len; ++i)
		{
			QByteArray ba;
			for (unsigned char j = 0; j < frameinfo[i].DataLen; ++j)
			{
				ba.append(frameinfo[i].Data[j]);
			}
			emit sigRecvData(m_arg.deviceIndex, m_arg.canIndex
				, frameinfo[i].ID, frameinfo[i].RemoteFlag
				, frameinfo[i].ExternFlag, ba, frameinfo[i].TimeStamp);
		}
	}
}

